<template>
  <div>
    <form class="form-signin" onsubmit=" return false">
      <div class="form-signin-heading text-center">
        <h1 class="sign-title">Sign In</h1>
        <img src="../../images/login-logo.png" alt=""/>
      </div>
      <div class="login-wrap">
        <p style="text-align:center;color:red">{{msg}}</p>
        <input type="text" v-model="form.user" class="form-control" placeholder="User ID" autofocus> <input type="password" v-model="form.password" class="form-control" placeholder="Password">
        <button v-on:click="login" class="btn btn-lg btn-login btn-block" type="submit">
          <i class="fa fa-check"></i>
        </button>
        <div class="registration">
          Not a member yet? <a class="" href="registration.html"> Signup </a>
        </div>
        <label class="checkbox"> <input v-model="form.remember" type="checkbox" value="remember-me"> 记住登陆
                <span class="pull-right">
                    <a data-toggle="modal" href="#myModal"> Forgot Password?</a>
                </span> </label>
      </div>
    </form>
  </div>
</template>
<script>
  export default{
    data(){
      return {
        form: {
          user: '',
          password: '',
          remember: true,
        },
        msg: ''
      }
    },
    mounted: function(){
      $( document.body ).addClass( 'login-body' )
    },
    created: function(){

    },
    methods: {
      login: function(){
        if( this.form.user == '' ){
          this.msg = '用户名不能为空'
          return;
        }
        if( this.form.password == '' ){
          this.msg = '密码不能为空'
          return;
        }
        this.$http.post('/admin/login/login',this.form).then(function(response){
          if(response.data.status){
            this.cookie.setCookie('token',response.data.data);
//            this.$router.go({name:'home'});
            window.location.href='/admin';
          }
        },function(response){
        }).bind(this);
      }
    }
  }
</script>